﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<CRM.Models.Turnovers>>" %>
<%@ Import Namespace="CRM.Models" %>
<%@ Import Namespace="CRM.Resourses" %>
<%@ Import Namespace="System.Threading" %>

<% Html.DevExpress().GridView(settings =>
                                    {
                                        settings.Name = "gdTurnovers";
                                        settings.KeyFieldName = "IdTurnover";
                                        settings.CallbackRouteValues =
                                            new { Controller = "Dictionaries", Action = "TurnoversPartial" };
                                        settings.SettingsPager.PageSize = 20;
                                       
                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.TurnoversAmount;
                                            column.FieldName = "Amount";
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.TurnoversPeriod;
                                            column.FieldName = "Period";
                                        });

                                        //
                                        //Добавление комбобоксов
                                        //
                                        settings.Columns.Add(column =>
                                        {
                                            column.FieldName = "IdLegalEntity";
                                            column.Caption = Resourses.LegalEntities;
                                            column.ColumnType = MVCxGridViewColumnType.ComboBox;

                                            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                            if (comboBoxProperties != null)
                                            {
                                               
                                                comboBoxProperties.DataSource =
                                                    DB.LegalEntities;

                                                comboBoxProperties.TextField = "Name";
                                                comboBoxProperties.ValueField = "IdLegalEntity";
                                                comboBoxProperties.ValueType = typeof(int);
                                            }
                                        });

                                        //
                                        //Добавление комбобоксов
                                        //
                                        settings.Columns.Add(column =>
                                        {
                                            column.FieldName = "IdDealerLegalEntity";
                                            column.Caption = Resourses.TurnoversDealers;
                                            column.ColumnType = MVCxGridViewColumnType.ComboBox;

                                            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                            if (comboBoxProperties != null)
                                            {
                                               
                                                comboBoxProperties.DataSource =
                                                    DB.LegalEntities;

                                                comboBoxProperties.TextField = "Name";
                                                comboBoxProperties.ValueField = "IdLegalEntity";
                                                comboBoxProperties.ValueType = typeof(int);
                                            }
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.FieldName = "IdTurnoverClassification";
                                            column.Caption = Resourses.TurnoverClassifications;
                                            column.ColumnType = MVCxGridViewColumnType.ComboBox;

                                            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                            if (comboBoxProperties != null)
                                            {
                                               
                                                comboBoxProperties.DataSource =
                                                    DB.GetLocalizedTurnoverClassificationsNames(Thread.CurrentThread.CurrentCulture.ToString());
                                                comboBoxProperties.TextField = "LocaLizedString";
                                                comboBoxProperties.ValueField = "Id";
                                                comboBoxProperties.ValueType = typeof(int);
                                            }
                                        });
                                        //конец комбобокса
                                        
                                        
                                        //
                                        //Добавление редактирования
                                        //
                                        settings.CommandColumn.Visible = true;
                                        settings.CommandColumn.NewButton.Visible = true;
                                        settings.CommandColumn.DeleteButton.Visible = true;
                                        settings.CommandColumn.EditButton.Visible = true;
                                        settings.SettingsBehavior.ConfirmDelete = true;
                                        settings.Settings.ShowFilterRow = true;
                                        settings.SettingsEditing.UpdateRowRouteValues = new { Controller = "Dictionaries", Action = "TurnoversPartialUpdate" };
                                        settings.SettingsEditing.AddNewRowRouteValues = new { Controller = "Dictionaries", Action = "TurnoversPartialAdd" };
                                        settings.SettingsEditing.DeleteRowRouteValues = new { Controller = "Dictionaries", Action = "TurnoversPartialDelete" };

                                        settings.SettingsEditing.Mode = GridViewEditingMode.EditFormAndDisplayRow;
                                        settings.Width = Unit.Percentage(100);

                                        
                                    })
       .Bind(Model).GetHtml();
%>

